/**
 * 	This file is part of GMGraphLib.
 * 
 * 	GMGraphLib is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *  
 *  GMGraphLib is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *  
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with GMGraphLib.  If not, see <http://www.gnu.org/licenses/>.
*/

package br.mendonca.gmgraphlib;

import junit.framework.TestCase;
import br.mendonca.gmgraphlib.exception.EmptyFileException;

/**
 * @author Gabriel Mendonça - gabrielgmendonca@gmail.com
 *
 */
public abstract class GraphsTest extends TestCase {

	private static final String PATH = "srcTest/";
	private static final String EMPTY_FILE = PATH + "empty_file.test";
	private static final String ONE_VERTEX = PATH + "one_vertex.test";
	private static final String ONE_EDGE = PATH + "one_edge.test";
	private static final String WRITE_GRAPH = PATH + "write_graph.test";

	protected static final int DATA_STRUCTURE = Graph.ADJACENCY_MATRIX;
	//protected static final int DATA_STRUCTURE = Graph.ADJACENCY_LIST;
	
	protected static final String TYPE = null;

	private Graph graph;
	
	public void testCreateGraphEmptyFile() throws Exception {
		try {
			GraphUtil.loadGraph(EMPTY_FILE, TYPE, DATA_STRUCTURE);
			fail("Deveria levantar uma EmptyFileException.");
			
		} catch (EmptyFileException e) {
			assertTrue(true);
			
		}
	}
	
	public void testCreateGraphOneVertex() throws Exception {
		graph = GraphUtil.loadGraph(ONE_VERTEX, TYPE, DATA_STRUCTURE);
		assertEquals(graph.getVertexList().get(0).index, 1);
	}
	
	public void testCreateGraphOneEdge() throws Exception {
		graph = GraphUtil.loadGraph(ONE_EDGE, TYPE, DATA_STRUCTURE);
		assertEquals(graph.getNeighbors(1).get(0).index, 3);
	}

	public void testWriteGraph() throws Exception {
		graph = Graph.getInstance(TYPE, 4, DATA_STRUCTURE);
		graph.addEdge(1, 2);
		graph.addEdge(1, 3);
		graph.addEdge(2, 4);
		graph.addEdge(3, 4);
		
		GraphUtil.saveGraph(graph, WRITE_GRAPH);
		Graph savedGraph = GraphUtil.loadGraph(WRITE_GRAPH, TYPE, DATA_STRUCTURE);
		
		assertEquals(graph.getVertexList().size(), savedGraph.getVertexList().size());
		
		EdgeList edgeList = graph.getEdgeList();
		while (edgeList.hasNext()) {
			Edge edge1 = edgeList.next();
			Edge edge2 = edgeList.next();
			
			assertEquals(edge1.toString(), edge2.toString());
		}
	}
	
}
